package kit.edu.lego.gruppe3.levels.endzone;

import kit.edu.lego.gruppe3.ComponentsRepository;
import kit.edu.lego.gruppe3.levels.LevelSelector;
import lejos.nxt.LightSensor;
import lejos.nxt.Sound;
import lejos.robotics.subsumption.Behavior;

public class EndZoneFinish implements Behavior
{

	
	private LightSensor lightS = ComponentsRepository.getInstance().getLightSensor();
	private static final short [] note = {2349,115, 0,5, 1760,165, 0,35};

	@Override
	public void action()
	{
		// either sumpf or line folower
		EndzoneSolver.setLevelCleared(true);
		for(int i=0;i <note.length; i+=2)
		{
	           short w = note[i+1];
	           int n = note[i];
	           if (n != 0) Sound.playTone(n, w*10);
	           try {
				Thread.sleep(w*10);
			} catch (InterruptedException e)
			{
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
	        }
		System.exit(-1);
		
	}

	@Override
	public void suppress()
	{

	}

	@Override
	public boolean takeControl()
	{
		return LevelSelector.getInstance().isEndZone() &&
			lightS.getLightValue() > ComponentsRepository.LIGHT_TRASHOLD;
	}

}